﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SmartProject.BusinessObjects;

namespace SmartProject.AppSpace
{
    public partial class ProductBacklog : UI.BasePage, UI.IDataSourcePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.SetPage("ProductBacklog", "The ProductBacklog page is a place where you can create all your desired work items from. You can also make use of this page to assign work items into a Sprint Cycle.");
                WorkGridView1.RefreshView(true);
            }
        }

        #region IDataSourcePage Members

        DataTable SmartProject.UI.IDataSourcePage.DataSource
        {
            get
            {
                Work work = new Work();
                // When status is either New or Assign, they will show up in ProductBacklog
                string conditional = String.Format(" ([StatusId] = {0} OR [StatusId] = {1}) AND wrk.[SprintId] IS NULL ", 
                    work.Statuses.GetId("New", false), work.Statuses.GetId("Assigned", false));
                return work.LoadWorks(conditional, "Created", true);
            }
        }

        public void Refresh()
        {
            WorkGridView1.RefreshView(true);
        }

        public override void RefreshPage(object obj)
        {
            // Do nothing.
        }

        #endregion

        public override AjaxControlToolkit.ModalPopupExtender Popup(string name)
        {
            return this.WorkGridView1.Popup;
        }
    }
}
